﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using ELGGAPI.Models;

namespace ELGGAPI.Data
{
    public class Provider
    {
        [Key]
        public int GameProviderID { get; set; }
        public string GameProviderName { get; set; }
        public string GameProviderDescription { get; set; }
        public string GameProviderUserName { get; set; }
        public string GameProviderPassword { get; set; }
    }

    public class ProviderModel
    {
        public int? id { get; set; }

        public string name { get; set; }

        public string description { get; set; }

        public string username { get; set; }

        public string password { get; set; }
    }
    public class ProviderDomainModles
    {


        public static Idclass AddProdiver(ProviderModel Provider)
        {
            using (var db = new ConELGG())
            {
                Provider provider;
                if (Provider.id == null || Provider.id <= 0)
                {
                    provider = db.my_gameprovider.Where(t => (t.GameProviderUserName == Provider.username)).FirstOrDefault();
                    if (provider == null)
                    {
                        provider = new Provider { GameProviderID = 0, GameProviderName = Provider.name, GameProviderDescription = Provider.description, GameProviderPassword = Provider.password, GameProviderUserName = Provider.username };
                        db.my_gameprovider.Add(provider);
                    }
                    else
                        return new Idclass() { id = -100 };
                }
                else
                {
                    provider = db.my_gameprovider.SingleOrDefault(t => t.GameProviderID == Provider.id);
                    provider.GameProviderName = Provider.name;
                    provider.GameProviderPassword = Provider.password;
                    provider.GameProviderUserName = Provider.username;
                    provider.GameProviderDescription = Provider.description;
                }

                db.SaveChanges();

                return new Idclass() { id = provider.GameProviderID };
            }

        }
    }
}
